<template>
    <!-- 优惠类型 -->
    <div class="container">
        <!-- 表单栏 -->
        <el-row>
            <el-col :span="24" class="dic-row">
                <avue-form ref="form" v-model="disForm.data" :option="disForm.option" class="yz-form"></avue-form>
                <button class="check-btn right-btn" @click="check"><img src="../../assets/imgs/operation_btn_icon_tijiao_default.png" alt="" class="btn-img">查询</button>
            </el-col>
        </el-row>
        <!-- 表格栏 -->
        <!-- 菜单 -->
        <el-row>
            <el-col :span="24" class="table-fun">
                <img src="../../assets/imgs/operation_icon_shuaxin_default.png" alt="" class="lf"><div class="lf choose-title fun-text" @click="refresh">刷新</div>
                <img src="../../assets/imgs/operation_icon_tianjia_default.png" alt="" class="lf"><div class="lf choose-title fun-text" @click="amWin=true;winTitle='添加'">添加</div>
                <img src="../../assets/imgs/operation_icon_xiugai_default.png" alt="" class="lf"><div class="lf choose-title fun-text" @click="amWin=true;winTitle='修改'">修改</div>
                <img src="../../assets/imgs/operation_icon_shanchu_default.png" alt="" class="lf"><div class="lf choose-title fun-text" @click="del">删除</div>
            </el-col>
        </el-row>
        <!-- 表格 -->
        <avue-crud ref="crud" :data="disTable.data" :option="disTable.option" @current-row-change="rowchange" :page="disTable.page" @current-change="disRow"></avue-crud>
        <!-- 弹窗 -->
        <div class="modal-win" v-show="amWin">
            <!-- 标题栏 -->
            <div class="closeWin" @click="amWin=false">X</div>
            <el-row class="add-title">
                <el-col :span="24">
                    <img src="../../assets/imgs/operation_bg_biaoti_default.png" alt=""><span class="add-text">{{winTitle}}</span>
                </el-col>
            </el-row>
            <!-- 表单栏 -->
            <avue-form ref="form" v-model="winForm.data" :option="winForm.option" class="yz-form"></avue-form>
            <button class="check-btn rf" @click="amWin=false">
            <img src="../../assets/imgs/operation_btn_icon_quxiao_default.png" alt="" class="btn-img">取消</button>
            <button class="check-btn rf" @click="winTitle=='添加'?add():mod()"><img src="../../assets/imgs/operation_btn_icon_tijiao_default.png" alt="" class="btn-img">确定</button>
        </div>
    </div>
</template>

<script>
const DIC={
    youxiao:[
        {
            label:"有效",
            value:1
        },
        {
            label:"无效",
            value:0
        },
    ]
}
export default {
    data(){
        return {
            disForm:{
                data:{},
                option:{
                    dicData:DIC,
                    column:[
                        {
                            label:"有效性",
                            prop:"isVaild",
                            type:"select",
                            dicData:"youxiao",
                            span:5
                        },
                        {
                            label:"名称",
                            prop:"name",
                            span:6
                        },
                    ]
                }
            },
            disTable:{
                page: {
                    pageSizes: [10],
                    total: 20,
                    currentPage: 1,
                    pageSize: 10,
                },
                data:[],
                option:{
                    highlightCurrentRow:true,
                    page:true,
                    menu:false,
                    align:'center',
                    menuAlign:'center',
                    column:[
                        {
                            label:"名称",
                            prop:"name"
                        },
                        {
                            label:"售价",
                            prop:"price"
                        },
                        {
                            label:"折扣",
                            prop:"discount_rate"
                        },
                        {
                            label:"可用次数",
                            prop:"available_count"
                        },
                        {
                            label:"备注",
                            prop:"remark"
                        },
                    ]
                }
            },
            currentRow:"",
            amWin:false,
            winTitle:"test",
            winForm:{
                data:{},
                option:{
                    column:[
                        {
                            label:"优惠名称",
                            prop:"discountName",
                            span:12
                        },
                        {
                            label:"售价",
                            prop:"sell",
                            span:12
                        },
                        {
                            label:"折扣",
                            prop:"discount",
                            span:12
                        },
                        {
                            label:"可用次数",
                            prop:"useTime",
                            span:12
                        },
                        {
                            label:"备注",
                            prop:"remark",
                            span:24
                        },
                    ]
                }
            }
        }
    },
    methods:{
        disRow(val){
            this.disTable.page.currentPage=val;
            this.getDisTable();
        },
        getDisTable(){
            this.postRequest("/disc/def/list",{
                rows:10,
                page:this.disTable.page.currentPage
            }).then(data=>{
                this.disTable.page.total=data.data.totalRow
                this.disTable.data=data.data.list;
            })
        },
        refresh(){
            this.getDisTable();
        },
        add(){
            this.getRequest("/disc/def/add?busCompany.id=&discountsDefines.name="+this.winForm.data.discountName+"&discountsDefines.price="+this.winForm.data.sell+"&discountsDefines.discount_rate="+this.winForm.data.discount+"&discountsDefines.available_count="+this.winForm.data.useTime+"&discountsDefines.remark="+this.winForm.data.remark).then(data=>{
                this.msgShow(data,this.getDisTable)
                this.amWin=false;
            })
        },
        mod(){
            this.getRequest("/disc/def/update?busCompany.id="+this.currentRow.id+"&discountsDefines.name="+this.winForm.data.discountName+"&discountsDefines.price="+this.winForm.data.sell+"&discountsDefines.discount_rate="+this.winForm.data.discount+"&discountsDefines.available_count="+this.winForm.data.useTime+"&discountsDefines.remark="+this.winForm.data.remark).then(data=>{
                this.msgShow(data,this.getDisTable);
                this.amWin=false;
            })
        },
        del(){},
        check(){
            this.postRequest("/disc/def/list",{
                filterRules:JSON.stringify([
                    {"field":"del_flag","op":"eq","value":this.disForm.data.isVaild},{"field":"name","op":"cn","value":this.disForm.data.name}
                ]),
                rows:10,
                page:this.disTable.page.currentPage
            }).then(data=>{
                this.disTable.page.total=data.data.totalRow
                this.disTable.data=data.data.list
            })
        },
        rowchange(val){
            this.currentRow=val;
            this.winForm.data.discountName=val.name;
            this.winForm.data.sell=val.price;
            this.winForm.data.discount=val.discount_rate;
            this.winForm.data.useTime=val.available_count;
            this.winForm.data.remark=val.remark;
        }
    },
    computed:{},
    watch:{
        winTitle(){
            if(this.winTitle=='添加'){
                this.winForm.data.discountName="";
                this.winForm.data.sell="";
                this.winForm.data.discount="";
                this.winForm.data.useTime="";
                this.winForm.data.remark="";
            }
        }
    },
    components:{},
   mounted(){
       this.$emit("sendActive", "2-1");
       this.getDisTable();
   }
}
</script>
<style scoped src="../../assets/css/financeManage/discountType.css">
</style>